<template>
  <div id="regionSelect">
    <div class="regionSelectItem">
      <span>办事地区:</span>
      <el-cascader
        class="regionSelectmin"
        v-model="regionPoint"
        :options="options"
        :props="{ expandTrigger: 'hover', value: 'area_id', label: 'area_name', children: 'child' }"
        @change="handleChange"
      ></el-cascader>
    </div>
    <div class="regionSelectItem" :key="node.id" v-for="node in pointList">
      <span>协办地区:</span>
      <el-cascader
        class="regionSelectmin"
        v-model="node.point"
        :options="node.option"
        :props="{ expandTrigger: 'hover', value: 'area_id', label: 'area_name', children: 'child' }"
        @change="handleChange"
      ></el-cascader>
      <i class="deleicon el-icon-error" @click="deleteSelectItem(node.nodeId)"></i>
    </div>
    <div @click="addSelectItem" class="regionSelectMore">+ 添加</div>
  </div>
</template>

<script>
  import { getAreaList } from '@/config/config';
  export default {
    name: 'regionSelect',
    data() {
      return {
        regionPoint: [],
        options: [],
        pointId: 0,
        pointList: []
      };
    },
    mounted() {
      this.options = getAreaList();
    },
    methods: {
      handleChange() {},
      addSelectItem() {
        this.pointList.push({
          point: '',
          nodeId: this.pointId++,
          option: getAreaList()
        });
      },
      //删除数组中符合条件的一项
      deleteSelectItem(nodeId) {
        this.pointList.splice(
          this.pointList.findIndex((item) => item.nodeId === nodeId),
          1
        );
      }
    }
  };
</script>

<style lang="scss" scoped>
  #regionSelect {
    width: 100%;
    height: 100%;
    padding-left: 40px;
    .regionSelectItem:hover {
      .deleicon {
        display: block;
        position: absolute;
        right: 10px;
        top: 13px;
        color: #dc4b3a;
        font-size: 16px;
        cursor: pointer;
      }
    }
    .regionSelectItem {
      span {
        padding-right: 8px;
      }
      display: inline-block;
      vertical-align: top;
      color: #222222;
      font-size: 16px;
      font-weight: 500;
      padding-right: 40px;
      padding-bottom: 20px;
      position: relative;
      .regionSelectmin {
        width: 240px;
      }
      .deleicon {
        display: none;
      }
    }
    .regionSelectMore:hover {
      color: #ffffff;
      background-color: $blue;
    }
    .regionSelectMore {
      display: inline-block;
      vertical-align: top;
      width: 100px;
      height: 38px;
      background: #ffffff;
      border: 1px solid $blue;
      opacity: 1;
      border-radius: 4px;
      text-align: center;
      line-height: 42px;
      color: $blue;
      font-size: 16px;
      cursor: pointer;
    }
  }
</style>
